package com.eliauk.demo.controller.read;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.enums.CellExtraTypeEnum;
import com.eliauk.demo.entity.read.DemoExtraData;
import com.eliauk.demo.utils.excel.listener.Demo8DataListener;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

@RestController
@RequestMapping("/demo8")
public class demo8Controller {
    /**
     * 读取excel文件是遇到额外信息，如超链接，批注，合并的单元格等
     * @param file excel 文件
     * @return
     * @throws IOException
     */
    @PostMapping("/import")
    public String importData(MultipartFile file) throws IOException {
        InputStream in  = file.getInputStream();
        EasyExcel.read(in, DemoExtraData.class,new Demo8DataListener())
                // 需要读取批注 默认不读取
                .extraRead(CellExtraTypeEnum.COMMENT)
                // 需要读取超链接 默认不读取
                .extraRead(CellExtraTypeEnum.HYPERLINK)
                // 需要读取合并单元格信息 默认不读取
                .extraRead(CellExtraTypeEnum.MERGE)
                .sheet()
                .doRead();
        return "success";
    }
}
